<?php
namespace Admin\Controller;
use Think\Controller;
class ConfigController extends BaseController {
    public function config_edit(){
        
        $logo=M('config')->where("con_title='logo'")->find();
        $this->assign('logo',$logo);

        $config_2=M('config')->where("con_title='备案号'")->find();
        $this->assign('config_2',$config_2);
        
       

        
        $this->assign('path',$path);
        if(I('post.')){
            if($_FILES['con_value']['size']){//如果有图片上传
                //获取旧图片
                $old_arr=M('config')->where("con_title='logo'")->find();
                $path='./Upload/'.$old_arr['con_value'];
                //删除旧图片
                //判断字段不为空并且图片存在
                if(!empty($old_arr) && file_exists($path)){
                    unlink($path);
                }
                //上传图片
                $upload=new \Think\Upload();
                $upload->exts=array('jpg','png','gif');
                $upload->rootPath='./Upload/';
                $upload->savePath='Logo/';
                $info=$upload->upload();
                if($info){
                    $data_1['con_value']=$info['con_value']['savepath'].$info['con_value']['savename'];
                }
            }
            $res_1=M('config')->where("con_title='logo'")->save($data_1);
            
            $data_2=array(
                'con_value'=>I('post.icp'),
            );
            $res_2=M('config')->where("con_title='备案号'")->save($data_2);

            // $data_3=array(
            //     'con_value'=>I('post.botton'),
            // );
            // $res_3=M('config')->where("con_title='botton'")->save($data_3);
            if($res_1 || $res_2){
                $this->success('编辑成功',U('Admin/Config/config_edit'));
                exit();
            }else{
                $this->error('数据输入有误');
                exit();
            }
        }

        $this->display();
    }
}